package com.shuhua.taskServer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shuhua.pojo.entity.TeamApply;
import com.shuhua.pojo.vo.TeamApplyVO;
import com.shuhua.pojo.vo.TeamMemberVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 班组申请Mapper接口
 */
@Mapper
public interface TeamApplyMapper extends BaseMapper<TeamApply> {
    
    /**
     * 查询班组申请列表（包含申请人详细信息）
     * @param teamId 班组ID
     * @return 申请列表
     */
    @Select("SELECT ta.id, ta.team_id, ta.craftsman_id, ta.apply_time, ta.status, " +
            "ta.audit_time, ta.audit_remark, " +
            "c.username, c.real_name, c.phone, c.avatar, " +
            "c.service_city, c.service_district, c.department, c.station, c.is_team_leader " +
            "FROM team_apply ta " +
            "LEFT JOIN craftsman c ON ta.craftsman_id = c.id " +
            "WHERE ta.team_id = #{teamId}")
    List<TeamApplyVO> findTeamAppliesWithCraftsman(@Param("teamId") Long teamId);
    
    /**
     * 查询工匠申请列表（包含申请人详细信息）
     * @param craftsmanId 工匠ID
     * @return 申请列表
     */
    @Select("SELECT ta.id, ta.team_id, ta.craftsman_id, ta.apply_time, ta.status, " +
            "ta.audit_time, ta.audit_remark, " +
            "c.username, c.real_name, c.phone, c.avatar, " +
            "c.service_city, c.service_district, c.department, c.station, c.is_team_leader " +
            "FROM team_apply ta " +
            "LEFT JOIN craftsman c ON ta.craftsman_id = c.id " +
            "WHERE ta.craftsman_id = #{craftsmanId}")
    List<TeamApplyVO> findCraftsmanAppliesWithDetail(@Param("craftsmanId") Long craftsmanId);
    
    /**
     * 查询申请人详细信息
     * @param craftsmanId 工匠ID
     * @return 工匠详细信息
     */
    @Select("SELECT c.id as craftsman_id, c.username, c.real_name, c.phone, c.avatar, " +
            "c.service_city, c.service_district, c.department, c.station, c.is_team_leader " +
            "FROM craftsman c " +
            "WHERE c.id = #{craftsmanId}")
    TeamMemberVO findCraftsmanDetail(@Param("craftsmanId") Long craftsmanId);
} 